/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bs.facturacion.dao;

import bs.facturacion.modelo.CircuitoFacturacion;
import bs.facturacion.modelo.CircuitoFacturacionPK;
import bs.facturacion.modelo.CodigoCircuitoFacturacion;
import bs.facturacion.modelo.ComprobanteFacturacion;
import bs.facturacion.modelo.ItemCircuitoFacturacion;
import bs.global.dao.BaseDAO;
import bs.stock.modelo.ComprobanteStock;
import bs.ventas.modelo.ComprobanteVenta;
import bs.tesoreria.modelo.ComprobanteTesoreria;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author Claudio
 */
@Stateless
public class CircuitoFacturacionDAO extends BaseDAO {
    
    public CircuitoFacturacion getCircuito(CircuitoFacturacionPK idPK){
        return em.find(CircuitoFacturacion.class, idPK);
    }

    public ComprobanteFacturacion getComprobanteFacturacion(String circom, String cirapl, String modcom, String codcom) {

        try{
            
            String sQuery = "SELECT i.comprobante FROM ItemCircuitoFacturacion i "
                    + "WHERE i.cirapl = '"+cirapl+"' "
                    + "AND i.circom = '"+circom+"' "
                    + "AND i.modulo = '"+modcom+"' "
                    + "AND i.codcom = '"+codcom+"' ";
            return queryObject(ComprobanteFacturacion.class, sQuery);

        }catch(Exception e){
            return null;
        }
       
    }

    public ComprobanteVenta getComprobanteVenta(String circom, String cirapl, String modcom, String codcom) {

        try{

            String sQuery = "SELECT i.comprobante FROM ItemCircuitoVenta i "
                    + "WHERE i.cirapl = '"+cirapl+"' "
                    + "AND i.circom = '"+circom+"' "
                    + "AND i.modulo = '"+modcom+"' "
                    + "AND i.codcom = '"+codcom+"' ";
            return queryObject(ComprobanteVenta.class, sQuery);

        }catch(Exception e){
            return null;
        }
    }

    public ComprobanteTesoreria getComprobanteTesoreria(String circom, String cirapl, String modcom, String codcom) {

        try{

            String sQuery = "SELECT i.comprobante FROM ItemCircuitoTesoreria i "
                    + "WHERE i.cirapl = '"+cirapl+"' "
                    + "AND i.circom = '"+circom+"' "
                    + "AND i.modulo = '"+modcom+"' "
                    + "AND i.codcom = '"+codcom+"' ";
            return queryObject(ComprobanteTesoreria.class, sQuery);

        }catch(Exception e){
            return null;
        }
    }

    public ComprobanteStock getComprobanteStock(String circom, String cirapl, String modcom, String codcom) {
        try{

            String sQuery = "SELECT i.comprobante FROM ItemCircuitoStock i "
                    + "WHERE i.cirapl = '"+cirapl+"' "
                    + "AND i.circom = '"+circom+"' "
                    + "AND i.modulo = '"+modcom+"' "
                    + "AND i.codcom = '"+codcom+"' ";
            return queryObject(ComprobanteStock.class, sQuery);

        }catch(Exception e){
            return null;
        }
    }

    public CodigoCircuitoFacturacion getCodigoCircuito(String codigo) {

        return em.find(CodigoCircuitoFacturacion.class, codigo);

    }

    public List<CodigoCircuitoFacturacion> getListaCodigoCircuito() {

        return getLista(CodigoCircuitoFacturacion.class, true, -1, -1);
    }

}
